//
//  NetAdvertice.m
//  carcareIOS
//
//  Created by wr on 15/12/3.
//  Copyright © 2015年 baozun. All rights reserved.
//

#import "NetAdvertice.h"
#import "AIUserInfo.h"
#import "AdverticePageModel.h"

@implementation NetAdvertice

+ (NetAdvertice *)loadAdverticeUrl:(NSString *)code
{
    return [__SELF request:@"/ad/query" withParams:@{@"code":code} type:REQUEST_POST ];
}

-(NSDictionary *)requestCommonParams{
    if (![USERINFO.session isNotNil]) {
        return nil;
    }
    return @{@"userid":@(USERINFO.userID),@"session":USERINFO.session};
}



+(void)loadAdverticesWithCode:(NSString *)code success:(void (^)(NSArray *))success fail:(void (^)())fail{
    [[NetAdvertice loadAdverticeUrl:code] requestSuccess:^(id JSON) {
        if ([JSON[@"infolist"] isKindOfClass:[NSArray class]]) {
            NSMutableArray * tempArr = [NSMutableArray arrayWithCapacity:[JSON[@"infolist"] count]];
            for (int index = 0; index < [JSON[@"infolist"] count]; index ++) {
                AdverticePageModel * model = [[AdverticePageModel alloc]initWithDic:JSON[@"infolist"][index]];
                [tempArr addObject:model];
            }
            if(success)success(tempArr);
        }else{
            if (fail) fail();
        }
    } failure:^(id JSON) {
        if (fail) {
            fail();
        }
    }];
}

@end
